package com.theima.mytreeset;

/**
 * @program: Myset
 * @description:
 * @author: xuejingjing
 * @create: 2021-06-08 21:45
 **/

//<>泛型 要和集合中的数据类型保持一致

/**
 * 1.定义一个空参构造方法
 * 2.实现Comparable<Student></>
 * 3.重写里面的compareTo方法
 */
public class Student  implements  Comparable<Student>{
    private String name;
    private int age;

    public Student() {
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    @Override
    public int compareTo(Student o) {
        //按照对象的年龄进行排序
          int result = this.age - o.age;
          return result;
    }
}
